home *** CD-ROM | disk | FTP | other *** search
- /* -*-C-*-
- *******************************************************************************
- *
- * File: EnhanceMail.m
- * RCS: $Header: /usr/local/lib/cvs/EnhanceMail/EnhanceMail.m,v 1.1.1.12 1996/04/08 22:30:51 cedman Exp $
- * Description:
- * Author: Carl Edman
- * Created: Fri Oct 13 11:48:05 1995
- * Modified: Mon Apr 8 11:09:31 1996 (Carl Edman) cedman@capitalist.princeton.edu
- * Language: C
- * Package: N/A
- * Status: Experimental (Do Not Distribute)
- *
- * (C) Copyright 1995, but otherwise this file is perfect freeware.
- *
- *******************************************************************************
- */
-
- #import "EnhanceMail.h"
- #import "Preferences.h"
- #import <ctype.h>
-
- NXBundle *EnhanceBundle=0;
- char *EnhanceVersion="X";
- char *regerrval=0;
-
- static const char *CVSName="$Name: release1_3 $";
- static BOOL windowsOnUnhide=NO;
-
- BOOL EnhanceControlP(void)
- {
- NXEvent *ev=[NXApp currentEvent];
- return ev && (ev->flags & NX_CONTROLMASK);
- }
-
- BOOL EnhanceShiftP(void)
- {
- NXEvent *ev=[NXApp currentEvent];
- return ev && (ev->flags & NX_SHIFTMASK);
- }
-
- BOOL EnhanceAlternateP(void)
- {
- NXEvent *ev=[NXApp currentEvent];
- return ev && (ev->flags & NX_ALTERNATEMASK);
- }
-
- @implementation EnhanceMail
- + finishLoading:(struct mach_header *)header
- {
- const char *beg=CVSName,*end=CVSName+strlen(CVSName);
-
- [self poseAs:[self superclass]];
- [NXApp changeClassTo:[self class]];
-
- while((beg<=end) && !isdigit(*beg)) beg++;
- while((beg<=end) && !isdigit(*end)) end--;
-
- if (beg<end)
- {
- char *c;
-
- end++;
- EnhanceVersion=strncpy(malloc(end-beg+1),beg,end-beg);
- EnhanceVersion[end-beg]='\0';
- for(c=EnhanceVersion;*c;c++) if (*c=='_') *c='.';
- }
-
- return self;
- }
-
- - initialCheck:sender
- {
- if ([self isHidden])
- {
- windowsOnUnhide=YES;
- }
- else
- {
- if (EnhanceLaunchMailboxes) [NXApp mailboxes:self];
- if (EnhanceLaunchAddresses) [NXApp address:self];
- }
- return [super initialCheck:sender];
- }
-
- - appDidUnhide:sender
- {
- if (windowsOnUnhide)
- {
- if (EnhanceLaunchMailboxes) [NXApp mailboxes:self];
- if (EnhanceLaunchAddresses) [NXApp address:self];
- windowsOnUnhide=NO;
- }
- return [super appDidUnhide:sender];
- }
-
- - (BOOL)updateCell:cell
- {
- return [super updateCell:cell];
- }
- @end
-
- @implementation Menu(EnhanceMail)
- - findCellWithTitle:(const char *)title
- {
- id cell=nil;
- int x, y, rows, cols;
- const char *c,*end;
-
- if (title==0) return nil;
- for(end=title;(*end) && (*end!='/');end++);
-
- [matrix getNumRows:&rows numCols:&cols];
- for(y=0;(y<rows) && (cell==nil);y++) for(x=0;(x<cols) && (cell==nil);x++)
- {
- if ((cell=[matrix cellAt:y:x])==nil) continue;
-
- if (((c=[cell title])==0)||(strncmp(title,c,end-title)!=0)||(c[end-title]!='\0'))
- cell=nil;
- }
-
- if (cell==nil)
- return nil;
- else if ((*end!='\0') && [cell hasSubmenu])
- return [[cell target] findCellWithTitle:end+1];
- else if (*end=='\0')
- return cell;
- else
- return nil;
- }
-
- - addSlashItem:(const char *)title action:(SEL)sel keyEquivalent:(unsigned short)code
- {
- id cell=nil;
- int x, y, rows, cols;
- const char *c,*end;
-
- if (title==0) return nil;
- for(end=title;(*end) && (*end!='/');end++);
-
- [matrix getNumRows:&rows numCols:&cols];
- for(y=0;(y<rows) && (cell==nil);y++) for(x=0;(x<cols) && (cell==nil);x++)
- {
- if ((cell=[matrix cellAt:y:x])==nil) continue;
-
- if (((c=[cell title])==0)||(strncmp(title,c,end-title)!=0)||(c[end-title]!='\0'))
- cell=nil;
- }
-
- if ((cell==nil) && (*end=='\0'))
- {
- cell=[self addItem:title action:sel keyEquivalent:code];
- [self display];
- return cell;
- }
- else if (cell==nil)
- {
- char *d=alloca(end-title+1);
- strncpy(d,title,end-title);
- d[end-title]='\0';
- cell=[self addItem:d action:0 keyEquivalent:0];
- [self setSubmenu:[[Menu alloc] initTitle:d] forItem:cell];
- [self display];
- return [[cell target] addSlashItem:end+1 action:sel keyEquivalent:code];
- }
- else if ((*end!='\0') && [cell hasSubmenu])
- return [[cell target] addSlashItem:end+1 action:sel keyEquivalent:code];
- else if (*end=='\0')
- return cell;
- else
- return nil;
- }
- @end
-
- @implementation Object(EnhanceMail)
- - changeClassTo:class
- {
- /* Don't try this at home, kids */
- isa=class;
- return self;
- }
- @end
-
- @implementation ButtonCell(EnhanceMail)
- - (int)state
- {
- return [self intValue];
- }
-
- - setState:(int)anInt
- {
- return [self setIntValue:anInt];
- }
- @end
-
- void regerror(char *s)
- {
- [NXApp logError:"regexp(3): %s",s];
- }
-